//****************************************************************
//Autor:   Yimy Juarez 
//       Gustavo Castro
//       Ulil Cojti
//       Josue Barrientos
//    
//Seccion: 10
//Nombre del Archivo: forms.java
//Fecha de Modificacion: 30/09/2012
//***************************************************************
package demo;

import java.io.IOException;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.LayerManager;
import org.netbeans.microedition.lcdui.pda.FileBrowser;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.lcdui.game.Sprite;
import org.netbeans.microedition.lcdui.pda.FileBrowser;
import demo.DemoMapa.*;
import java.util.Timer;

/**
 * @author miriam
 */
public class forms extends MIDlet implements CommandListener {
    
    private boolean midletPaused = false;
    private DemoMapa  gameCanvas;
    private DemoPrueba gamePrueba;
    private Command atras;
    private Command atras2;
    private Thread t;
    private Displayable x;
    private Command item1;
    private Command item2;
    private Command item3;
    private Command item4;
    private LayerManager[] layers;
    private Display d;
    private Sprite sprite;
    private Timer timer;
    private String str;

    int bandera=0;
    int contador=0;
    Sprite spr;
    String url = "http://localhost/midlet/hello.txt";
    
    
//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private List list;
    private List list1;
    private List list2;
    private TextBox textBox;
    private FileBrowser fileBrowser;
    private List list3;
    private Form form;
    private TextBox textBox1;
    private Command exitCommand;
    private Command okCommand;
    private Command backCommand;
    private Command okCommand1;
    private Command backCommand1;
    private Command okCommand2;
    private Command backCommand2;
    private Command backCommand3;
    private Command backCommand4;
    private Command backCommand5;
    private Command okCommand3;
    private Command backCommand6;
    private Command okCommand4;
    private Command okCommand5;
    private Command okCommand6;
    private Command backCommand7;
    private Command okCommand7;
    private Command backCommand8;
    private Command okCommand8;
    private Command backCommand10;
    private Command backCommand9;
//</editor-fold>//GEN-END:|fields|0|
    /**
     * The forms constructor.
     */
    public forms() {

    }

//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
//</editor-fold>//GEN-END:|methods|0|
//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initializes the application. It is called only once when the MIDlet is
     * started. The method is called before the
     * <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
//</editor-fold>//GEN-END:|0-initialize|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        layers = new LayerManager[4];
    
        switchDisplayable(null, getList());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
//</editor-fold>//GEN-END:|3-startMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
//</editor-fold>//GEN-END:|4-resumeMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The
     * <code>display</code> instance is taken from
     * <code>getDisplay</code> method. This method is used by all actions in the
     * design for switching displayable.
     *
     * @param alert the Alert which is temporarily set to the display;
     * if <code>null</code>, then <code>nextDisplayable</code> is set
     * immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
//</editor-fold>//GEN-END:|5-switchDisplayable|2|


//<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|21-getter|0|21-preInit
    /**
     * Returns an initialized instance of exitCommand component.
     *
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|21-getter|0|21-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|21-getter|1|21-postInit
            // write post-init user code here
        }//GEN-BEGIN:|21-getter|2|
        return exitCommand;
    }
//</editor-fold>//GEN-END:|21-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand ">//GEN-BEGIN:|23-getter|0|23-preInit
    /**
     * Returns an initialized instance of okCommand component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand() {
        if (okCommand == null) {//GEN-END:|23-getter|0|23-preInit
            // write pre-init user code here
            okCommand = new Command("Ok", Command.OK, 0);//GEN-LINE:|23-getter|1|23-postInit
            // write post-init user code here
        }//GEN-BEGIN:|23-getter|2|
        return okCommand;
    }
//</editor-fold>//GEN-END:|23-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|31-getter|0|31-preInit
    /**
     * Returns an initialized instance of backCommand component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|31-getter|0|31-preInit
            // write pre-init user code here
            backCommand = new Command("Back", Command.BACK, 0);//GEN-LINE:|31-getter|1|31-postInit
            // write post-init user code here
        }//GEN-BEGIN:|31-getter|2|
        return backCommand;
    }
//</editor-fold>//GEN-END:|31-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand1 ">//GEN-BEGIN:|33-getter|0|33-preInit
    /**
     * Returns an initialized instance of okCommand1 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand1() {
        if (okCommand1 == null) {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            okCommand1 = new Command("Ok", Command.OK, 0);//GEN-LINE:|33-getter|1|33-postInit
            // write post-init user code here
        }//GEN-BEGIN:|33-getter|2|
        return okCommand1;
    }
//</editor-fold>//GEN-END:|33-getter|2|
    
//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|39-getter|0|39-preInit
    /**
     * Returns an initialized instance of backCommand1 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|39-getter|0|39-preInit
            // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 0);//GEN-LINE:|39-getter|1|39-postInit
            // write post-init user code here
        }//GEN-BEGIN:|39-getter|2|
        return backCommand1;
    }
//</editor-fold>//GEN-END:|39-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand2 ">//GEN-BEGIN:|41-getter|0|41-preInit
    /**
     * Returns an initialized instance of okCommand2 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand2() {
        if (okCommand2 == null) {//GEN-END:|41-getter|0|41-preInit
            // write pre-init user code here
            okCommand2 = new Command("Ok", Command.OK, 0);//GEN-LINE:|41-getter|1|41-postInit
            // write post-init user code here
        }//GEN-BEGIN:|41-getter|2|
        return okCommand2;
    }
//</editor-fold>//GEN-END:|41-getter|2|
//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction

    /**
     * Called by a system to indicated that a command has been invoked on a
     * particular displayable.
     *
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        
        if (displayable == fileBrowser) {//GEN-BEGIN:|7-commandAction|1|91-preAction
            if (command == FileBrowser.SELECT_FILE_COMMAND) {//GEN-END:|7-commandAction|1|91-preAction
                // write pre-action user code here
                switchDisplayable(null, getTextBox());//GEN-LINE:|7-commandAction|2|91-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|128-preAction
        } else if (displayable == form) {
            if (command == backCommand10) {//GEN-END:|7-commandAction|3|128-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|4|128-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|5|16-preAction
        } else if (displayable == list) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|5|16-preAction
                // write pre-action user code here
                listAction();//GEN-LINE:|7-commandAction|6|16-postAction
                // write post-action user code here
            } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|7|22-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|8|22-postAction
                // write post-action user code here
            } else if (command == okCommand) {//GEN-LINE:|7-commandAction|9|24-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|10|24-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|11|37-preAction
        } else if (displayable == list1) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|11|37-preAction
                // write pre-action user code here
                list1Action();//GEN-LINE:|7-commandAction|12|37-postAction
                // write post-action user code here
            } else if (command == backCommand1) {//GEN-LINE:|7-commandAction|13|40-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|14|40-postAction
                // write post-action user code here
            } else if (command == okCommand2) {//GEN-LINE:|7-commandAction|15|42-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|16|42-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|17|76-preAction
        } else if (displayable == list2) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|17|76-preAction
                // write pre-action user code here
                list2Action();//GEN-LINE:|7-commandAction|18|76-postAction
                // write post-action user code here
            } else if (command == backCommand6) {//GEN-LINE:|7-commandAction|19|79-preAction
                // write pre-action user code here
                switchDisplayable(null, getList3());//GEN-LINE:|7-commandAction|20|79-postAction
                // write post-action user code here
            } else if (command == okCommand5) {//GEN-LINE:|7-commandAction|21|81-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|22|81-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|23|105-preAction
        } else if (displayable == list3) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|23|105-preAction
                // write pre-action user code here
                list3Action();//GEN-LINE:|7-commandAction|24|105-postAction
                // write post-action user code here
            } else if (command == backCommand8) {//GEN-LINE:|7-commandAction|25|108-preAction
                // write pre-action user code here
                switchDisplayable(null, getList());//GEN-LINE:|7-commandAction|26|108-postAction
                // write post-action user code here
            } else if (command == okCommand7) {//GEN-LINE:|7-commandAction|27|110-preAction
                // write pre-action user code here
//GEN-LINE:|7-commandAction|28|110-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|29|99-preAction
        } else if (displayable == textBox) {
            if (command == backCommand7) {//GEN-END:|7-commandAction|29|99-preAction
                // write pre-action user code here
                textBox=null;
                switchDisplayable(null, getList3());//GEN-LINE:|7-commandAction|30|99-postAction
                // write post-action user code here
            } else if (command == okCommand6) {//GEN-LINE:|7-commandAction|31|102-preAction
                // write pre-action user code here
                switchDisplayable(null, getList2());//GEN-LINE:|7-commandAction|32|102-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|33|122-preAction
        } else if (displayable == textBox1) {
            if (command == backCommand9) {//GEN-END:|7-commandAction|33|122-preAction
                // write pre-action user code here
                switchDisplayable(null, getList3());//GEN-LINE:|7-commandAction|34|122-postAction
                // write post-action user code here
            } else if (command == okCommand8) {//GEN-LINE:|7-commandAction|35|120-preAction
                // write pre-action user code here
                switchDisplayable(null, getList2());//GEN-LINE:|7-commandAction|36|120-postAction
                // write post-action user code here
                str = getTextBox1().getString();
            }//GEN-BEGIN:|7-commandAction|37|7-postCommandAction
        }//GEN-END:|7-commandAction|37|7-postCommandAction
        // write post-action user code here
        else{ 
            if(command== atras)
            {   
                try {
                    this.gameCanvas.ocultarMarcador();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }

                //this.gameCanvas.nino.setVisible(true);                
                layers[contador]= this.gameCanvas.lm;

                listAction();
                  contador++;
                  contador = contador % 4;
            }
            else if(command==atras2){
                listAction();
                
            }
            else if(command == item1){
                try {
                    this.gameCanvas.setArbusto();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            else if(command == item2){
            try {
                    this.gameCanvas.setEdificio();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }

            }
            else if(command == item3){
               try {
                    this.gameCanvas.setArbol();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }

            }            
            else if(command == item4){
                                try {
                    this.gameCanvas.setFaro();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }

            }
            
       }
    }//GEN-BEGIN:|7-commandAction|38|
//</editor-fold>//GEN-END:|7-commandAction|38|




//<editor-fold defaultstate="collapsed" desc=" Generated Getter: list ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initialized instance of list component.
     *
     * @return the initialized component instance
     */
    public List getList() {
        if (list == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            list = new List("MENU", Choice.IMPLICIT);//GEN-BEGIN:|14-getter|1|14-postInit
            list.append("Jugar", null);
            list.append("Mapas", null);
            list.append("Instrucciones", null);
            list.addCommand(getExitCommand());
            list.addCommand(getOkCommand());
            list.setCommandListener(this);
            list.setSelectedFlags(new boolean[]{false, false, false});//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return list;
    }
//</editor-fold>//GEN-END:|14-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: listAction ">//GEN-BEGIN:|14-action|0|14-preAction
    /**
     * Performs an action assigned to the selected list element in the list
     * component.
     */
    public void listAction() {//GEN-END:|14-action|0|14-preAction
        // enter pre-action user code here
        String __selectedString = getList().getString(getList().getSelectedIndex());//GEN-BEGIN:|14-action|1|18-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Jugar")) {//GEN-END:|14-action|1|18-preAction
                // write pre-action user code here                                     
//                this.gamePrueba.setCommandListener(this);                             

                switchDisplayable(null, getList3());//GEN-LINE:|14-action|2|18-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Mapas")) {//GEN-LINE:|14-action|3|19-preAction
                // write pre-action user code here
                switchDisplayable(null, getList1());//GEN-LINE:|14-action|4|19-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Instrucciones")) {//GEN-LINE:|14-action|5|20-preAction
                // write pre-action user code here
                switchDisplayable(null, getForm());//GEN-LINE:|14-action|6|20-postAction
                // write post-action user code here
            }//GEN-BEGIN:|14-action|7|14-postAction
        }//GEN-END:|14-action|7|14-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|14-action|8|
//</editor-fold>//GEN-END:|14-action|8|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: list1 ">//GEN-BEGIN:|36-getter|0|36-preInit
    /**
     * Returns an initialized instance of list1 component.
     *
     * @return the initialized component instance
     */
    public List getList1() {
        if (list1 == null) {//GEN-END:|36-getter|0|36-preInit
            // write pre-init user code here
            list1 = new List("CREACIOND DE MAPAS", Choice.IMPLICIT);//GEN-BEGIN:|36-getter|1|36-postInit
            list1.append("Crear mapa", null);
            list1.addCommand(getBackCommand1());
            list1.addCommand(getOkCommand2());
            list1.setCommandListener(this);
            list1.setSelectedFlags(new boolean[]{false});//GEN-END:|36-getter|1|36-postInit
            // write post-init user code here
        }//GEN-BEGIN:|36-getter|2|
        return list1;
    }
//</editor-fold>//GEN-END:|36-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: list1Action ">//GEN-BEGIN:|36-action|0|36-preAction
    /**
     * Performs an action assigned to the selected list element in the list1
     * component.
     */
    public void list1Action() {//GEN-END:|36-action|0|36-preAction
        // enter pre-action user code here
        String __selectedString = getList1().getString(getList1().getSelectedIndex());//GEN-BEGIN:|36-action|1|43-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Crear mapa")) {//GEN-END:|36-action|1|43-preAction
                 // write pre-action user code here
                this.gameCanvas = new DemoMapa(this);                    
                this.gameCanvas.addCommand(getRegresa());
                this.gameCanvas.addCommand(getItem1());
                this.gameCanvas.addCommand(getItem2());
                this.gameCanvas.addCommand(getItem3());
                this.gameCanvas.addCommand(getItem4());
                
                this.gameCanvas.setCommandListener(this);                             
                this.t = new Thread(gameCanvas);
                t.start();
                d = Display.getDisplay(this);
                d.setCurrent(gameCanvas);                    
//GEN-LINE:|36-action|2|43-postAction
                // write post-action user code here
            }//GEN-BEGIN:|36-action|3|36-postAction
        }//GEN-END:|36-action|3|36-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|36-action|4|
//</editor-fold>//GEN-END:|36-action|4|
    public Command getRegresa() {
        if (atras == null) {                                 
            // write pre-init user code here
            atras = new Command("Back", Command.BACK, 0);                                   
            // write post-init user code here
        }                         
        return atras;
    }
    public Command getRegresa2() {
        if (atras2 == null) {                                 
            // write pre-init user code here
            atras2 = new Command("Back", Command.BACK, 0);                                   
            // write post-init user code here
        }                         
        return atras2;
    }

    public Command getItem1() {
        if (item1 == null) {                                 
            // write pre-init user code here
            item1 = new Command("Item 1", Command.ITEM, 1);                                   
            // write post-init user code here
        }                         
        return item1;
    }
      public Command getItem2() {
        if (item2 == null) {                                 
            // write pre-init user code here
            item2 = new Command("Item 2", Command.ITEM, 2);                                   
            // write post-init user code here
        }                         
        return item2;
    }
       public Command getItem3() {
        if (item3 == null) {                                 
            // write pre-init user code here
            item3 = new Command("Item 3", Command.ITEM, 3);                                   
            // write post-init user code here
        }                         
        return item3;
    }
       public Command getItem4() {
        if (item4 == null) {                                 
            // write pre-init user code here
            item4 = new Command("Item 4", Command.ITEM, 4);                                   
            // write post-init user code here
        }                         
        return item4;
    }


//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand2 ">//GEN-BEGIN:|55-getter|0|55-preInit
    /**
     * Returns an initialized instance of backCommand2 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {//GEN-END:|55-getter|0|55-preInit
            // write pre-init user code here
            backCommand2 = new Command("Back", Command.BACK, 0);//GEN-LINE:|55-getter|1|55-postInit
            // write post-init user code here
        }//GEN-BEGIN:|55-getter|2|
        return backCommand2;
    }
//</editor-fold>//GEN-END:|55-getter|2|





//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand3 ">//GEN-BEGIN:|59-getter|0|59-preInit
    /**
     * Returns an initialized instance of backCommand3 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand3() {
        if (backCommand3 == null) {//GEN-END:|59-getter|0|59-preInit
            // write pre-init user code here
            backCommand3 = new Command("Back", Command.BACK, 0);//GEN-LINE:|59-getter|1|59-postInit
            // write post-init user code here
        }//GEN-BEGIN:|59-getter|2|
        return backCommand3;
    }
//</editor-fold>//GEN-END:|59-getter|2|



//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand3 ">//GEN-BEGIN:|66-getter|0|66-preInit
    /**
     * Returns an initialized instance of okCommand3 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand3() {
        if (okCommand3 == null) {//GEN-END:|66-getter|0|66-preInit
            // write pre-init user code here
            okCommand3 = new Command("Ok", Command.OK, 0);//GEN-LINE:|66-getter|1|66-postInit
            // write post-init user code here
        }//GEN-BEGIN:|66-getter|2|
        return okCommand3;
    }
//</editor-fold>//GEN-END:|66-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand4 ">//GEN-BEGIN:|68-getter|0|68-preInit
    /**
     * Returns an initialized instance of backCommand4 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand4() {
        if (backCommand4 == null) {//GEN-END:|68-getter|0|68-preInit
            // write pre-init user code here
            backCommand4 = new Command("Back", Command.BACK, 0);//GEN-LINE:|68-getter|1|68-postInit
            // write post-init user code here
        }//GEN-BEGIN:|68-getter|2|
        return backCommand4;
    }
//</editor-fold>//GEN-END:|68-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: list2 ">//GEN-BEGIN:|75-getter|0|75-preInit
    /**
     * Returns an initialized instance of list2 component.
     *
     * @return the initialized component instance
     */
    public List getList2() {
        if (list2 == null) {//GEN-END:|75-getter|0|75-preInit
            // write pre-init user code here
            list2 = new List("MAPAS", Choice.IMPLICIT);//GEN-BEGIN:|75-getter|1|75-postInit
            list2.append("Mapa 1", null);
            list2.append("Mapa 2", null);
            list2.append("Mapa 3", null);
            list2.append("Mapa 4", null);
            list2.addCommand(getBackCommand6());
            list2.addCommand(getOkCommand5());
            list2.setCommandListener(this);
            list2.setSelectedFlags(new boolean[]{false, false, false, false});//GEN-END:|75-getter|1|75-postInit
            // write post-init user code here
        }//GEN-BEGIN:|75-getter|2|
        return list2;
    }
//</editor-fold>//GEN-END:|75-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: list2Action ">//GEN-BEGIN:|75-action|0|75-preAction
    /**
     * Performs an action assigned to the selected list element in the list2
     * component.
     */
    public void list2Action() {//GEN-END:|75-action|0|75-preAction
        // enter pre-action user code here
        String __selectedString = getList2().getString(getList2().getSelectedIndex());//GEN-BEGIN:|75-action|1|83-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Mapa 1")) {//GEN-END:|75-action|1|83-preAction
                // write pre-action user code here
                this.gamePrueba = new DemoPrueba(layers[0],str);                    
                this.gamePrueba.addCommand(getRegresa2());                
                this.gamePrueba.setCommandListener(this);                             
                this.t = new Thread(gamePrueba);
                t.start();
                d = Display.getDisplay(this);
                d.setCurrent(gamePrueba);                    
//GEN-LINE:|75-action|2|83-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Mapa 2")) {//GEN-LINE:|75-action|3|84-preAction
                // write pre-action user code here
                this.gamePrueba = new DemoPrueba(layers[1],str);                    
                this.gamePrueba.addCommand(getRegresa2());                
                this.gamePrueba.setCommandListener(this);                             
                this.t = new Thread(gamePrueba);
                t.start();
                d = Display.getDisplay(this);
                d.setCurrent(gamePrueba);                    

//GEN-LINE:|75-action|4|84-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Mapa 3")) {//GEN-LINE:|75-action|5|85-preAction
                // write pre-action user code here
                this.gamePrueba = new DemoPrueba(layers[2],str);                    
                this.gamePrueba.addCommand(getRegresa2());                
                this.gamePrueba.setCommandListener(this);                             
                this.t = new Thread(gamePrueba);
                t.start();
                d = Display.getDisplay(this);
                d.setCurrent(gamePrueba);                    

//GEN-LINE:|75-action|6|85-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Mapa 4")) {//GEN-LINE:|75-action|7|86-preAction
                // write pre-action user code here
                this.gamePrueba = new DemoPrueba(layers[3],str);                    
                this.gamePrueba.addCommand(getRegresa2());                
                this.gamePrueba.setCommandListener(this);                             
                this.t = new Thread(gamePrueba);
                t.start();
                d = Display.getDisplay(this);
                d.setCurrent(gamePrueba);                    

//GEN-LINE:|75-action|8|86-postAction
                // write post-action user code here
            }//GEN-BEGIN:|75-action|9|75-postAction
        }//GEN-END:|75-action|9|75-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|75-action|10|
//</editor-fold>//GEN-END:|75-action|10|


//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand5 ">//GEN-BEGIN:|71-getter|0|71-preInit
    /**
     * Returns an initialized instance of backCommand5 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand5() {
        if (backCommand5 == null) {//GEN-END:|71-getter|0|71-preInit
            // write pre-init user code here
            backCommand5 = new Command("Back", Command.BACK, 0);//GEN-LINE:|71-getter|1|71-postInit
            // write post-init user code here
        }//GEN-BEGIN:|71-getter|2|
        return backCommand5;
    }
//</editor-fold>//GEN-END:|71-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand4 ">//GEN-BEGIN:|73-getter|0|73-preInit
    /**
     * Returns an initialized instance of okCommand4 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand4() {
        if (okCommand4 == null) {//GEN-END:|73-getter|0|73-preInit
            // write pre-init user code here
            okCommand4 = new Command("Ok", Command.OK, 0);//GEN-LINE:|73-getter|1|73-postInit
            // write post-init user code here
        }//GEN-BEGIN:|73-getter|2|
        return okCommand4;
    }
//</editor-fold>//GEN-END:|73-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand6 ">//GEN-BEGIN:|78-getter|0|78-preInit
    /**
     * Returns an initialized instance of backCommand6 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand6() {
        if (backCommand6 == null) {//GEN-END:|78-getter|0|78-preInit
            // write pre-init user code here
            backCommand6 = new Command("Back", Command.BACK, 0);//GEN-LINE:|78-getter|1|78-postInit
            // write post-init user code here
        }//GEN-BEGIN:|78-getter|2|
        return backCommand6;
    }
//</editor-fold>//GEN-END:|78-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand5 ">//GEN-BEGIN:|80-getter|0|80-preInit
    /**
     * Returns an initialized instance of okCommand5 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand5() {
        if (okCommand5 == null) {//GEN-END:|80-getter|0|80-preInit
            // write pre-init user code here
            okCommand5 = new Command("Ok", Command.OK, 0);//GEN-LINE:|80-getter|1|80-postInit
            // write post-init user code here
        }//GEN-BEGIN:|80-getter|2|
        return okCommand5;
    }
//</editor-fold>//GEN-END:|80-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: fileBrowser ">//GEN-BEGIN:|90-getter|0|90-preInit
    /**
     * Returns an initialized instance of fileBrowser component.
     *
     * @return the initialized component instance
     */
    public FileBrowser getFileBrowser() {
        if (fileBrowser == null) {//GEN-END:|90-getter|0|90-preInit
            // write pre-init user code here
            fileBrowser = new FileBrowser(getDisplay());//GEN-BEGIN:|90-getter|1|90-postInit
            fileBrowser.setTitle("fileBrowser");
            fileBrowser.setCommandListener(this);
            fileBrowser.addCommand(FileBrowser.SELECT_FILE_COMMAND);//GEN-END:|90-getter|1|90-postInit
            // write post-init user code here
        }//GEN-BEGIN:|90-getter|2|
        return fileBrowser;
    }
//</editor-fold>//GEN-END:|90-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textBox ">//GEN-BEGIN:|95-getter|0|95-preInit
    /**
     * Returns an initialized instance of textBox component.
     *
     * @return the initialized component instance
     */
    public TextBox getTextBox() {
        if (textBox == null) {//GEN-END:|95-getter|0|95-preInit
            // write pre-init user code here
            url = fileBrowser.getSelectedFileURL();
            try{
                
            FileConnection fc = (FileConnection)
            Connector.open(url);
            if(!fc.exists()){
                throw new IOException("El archivo no existe");
            }
            InputStream fis = fc.openInputStream();
            byte[] b = new byte[1024];
            int lenght = fis.read(b,0,1024);
            fis.close();
            fc.close();
            
                textBox = new TextBox("CODIGO", null, 9999, TextField.ANY);//GEN-BEGIN:|95-getter|1|95-postInit
                textBox.addCommand(getBackCommand7());
                textBox.addCommand(getOkCommand6());
                textBox.setCommandListener(this);//GEN-END:|95-getter|1|95-postInit
            // write post-init user code here
            if(lenght >0){
                textBox.setString(new String(b,0,lenght));    
                str = textBox.getString();
            }
            Display.getDisplay(this).setCurrent(textBox);
            
            }
            catch(Exception e){}
        }//GEN-BEGIN:|95-getter|2|
        return textBox;
    }
//</editor-fold>//GEN-END:|95-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand7 ">//GEN-BEGIN:|98-getter|0|98-preInit
    /**
     * Returns an initialized instance of backCommand7 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand7() {
        if (backCommand7 == null) {//GEN-END:|98-getter|0|98-preInit
            // write pre-init user code here
            backCommand7 = new Command("Back", Command.BACK, 0);//GEN-LINE:|98-getter|1|98-postInit
            // write post-init user code here
        }//GEN-BEGIN:|98-getter|2|
        return backCommand7;
    }
//</editor-fold>//GEN-END:|98-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: list3 ">//GEN-BEGIN:|104-getter|0|104-preInit
    /**
     * Returns an initialized instance of list3 component.
     *
     * @return the initialized component instance
     */
    public List getList3() {
        if (list3 == null) {//GEN-END:|104-getter|0|104-preInit
            // write pre-init user code here
            list3 = new List("CODIFICAR", Choice.IMPLICIT);//GEN-BEGIN:|104-getter|1|104-postInit
            list3.append("Importar c\u00F3digo", null);
            list3.append("Codificar aqu\u00ED", null);
            list3.addCommand(getBackCommand8());
            list3.addCommand(getOkCommand7());
            list3.setCommandListener(this);
            list3.setSelectedFlags(new boolean[]{false, false});//GEN-END:|104-getter|1|104-postInit
            // write post-init user code here
        }//GEN-BEGIN:|104-getter|2|
        return list3;
    }
//</editor-fold>//GEN-END:|104-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: list3Action ">//GEN-BEGIN:|104-action|0|104-preAction
    /**
     * Performs an action assigned to the selected list element in the list3
     * component.
     */
    public void list3Action() {//GEN-END:|104-action|0|104-preAction
        // enter pre-action user code here
        String __selectedString = getList3().getString(getList3().getSelectedIndex());//GEN-BEGIN:|104-action|1|111-preAction
        if (__selectedString != null) {
            if (__selectedString.equals("Importar c\u00F3digo")) {//GEN-END:|104-action|1|111-preAction
                // write pre-action user code here
                switchDisplayable(null, getFileBrowser());//GEN-LINE:|104-action|2|111-postAction
                // write post-action user code here
            } else if (__selectedString.equals("Codificar aqu\u00ED")) {//GEN-LINE:|104-action|3|112-preAction
                // write pre-action user code here
                switchDisplayable(null, getTextBox1());//GEN-LINE:|104-action|4|112-postAction
                // write post-action user code here
            }//GEN-BEGIN:|104-action|5|104-postAction
        }//GEN-END:|104-action|5|104-postAction
        // enter post-action user code here
    }//GEN-BEGIN:|104-action|6|
//</editor-fold>//GEN-END:|104-action|6|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand6 ">//GEN-BEGIN:|101-getter|0|101-preInit
    /**
     * Returns an initialized instance of okCommand6 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand6() {
        if (okCommand6 == null) {//GEN-END:|101-getter|0|101-preInit
            // write pre-init user code here
            okCommand6 = new Command("Ok", Command.OK, 0);//GEN-LINE:|101-getter|1|101-postInit
            // write post-init user code here
        }//GEN-BEGIN:|101-getter|2|
        return okCommand6;
    }
//</editor-fold>//GEN-END:|101-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand8 ">//GEN-BEGIN:|107-getter|0|107-preInit
    /**
     * Returns an initialized instance of backCommand8 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand8() {
        if (backCommand8 == null) {//GEN-END:|107-getter|0|107-preInit
            // write pre-init user code here
            backCommand8 = new Command("Back", Command.BACK, 0);//GEN-LINE:|107-getter|1|107-postInit
            // write post-init user code here
        }//GEN-BEGIN:|107-getter|2|
        return backCommand8;
    }
//</editor-fold>//GEN-END:|107-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand7 ">//GEN-BEGIN:|109-getter|0|109-preInit
    /**
     * Returns an initialized instance of okCommand7 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand7() {
        if (okCommand7 == null) {//GEN-END:|109-getter|0|109-preInit
            // write pre-init user code here
            okCommand7 = new Command("Ok", Command.OK, 0);//GEN-LINE:|109-getter|1|109-postInit
            // write post-init user code here
        }//GEN-BEGIN:|109-getter|2|
        return okCommand7;
    }
//</editor-fold>//GEN-END:|109-getter|2|



//<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand8 ">//GEN-BEGIN:|119-getter|0|119-preInit
    /**
     * Returns an initialized instance of okCommand8 component.
     *
     * @return the initialized component instance
     */
    public Command getOkCommand8() {
        if (okCommand8 == null) {//GEN-END:|119-getter|0|119-preInit
            // write pre-init user code here
            okCommand8 = new Command("Ok", Command.OK, 0);//GEN-LINE:|119-getter|1|119-postInit
            // write post-init user code here
        }//GEN-BEGIN:|119-getter|2|
        return okCommand8;
    }
//</editor-fold>//GEN-END:|119-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand9 ">//GEN-BEGIN:|121-getter|0|121-preInit
    /**
     * Returns an initialized instance of backCommand9 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand9() {
        if (backCommand9 == null) {//GEN-END:|121-getter|0|121-preInit
            // write pre-init user code here
            backCommand9 = new Command("Back", Command.BACK, 0);//GEN-LINE:|121-getter|1|121-postInit
            // write post-init user code here
        }//GEN-BEGIN:|121-getter|2|
        return backCommand9;
    }
//</editor-fold>//GEN-END:|121-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GEN-BEGIN:|126-getter|0|126-preInit
    /**
     * Returns an initialized instance of form component.
     *
     * @return the initialized component instance
     */
    public Form getForm() {
        if (form == null) {//GEN-END:|126-getter|0|126-preInit
            // write pre-init user code here
            form = new Form("Instrucciones", new Item[]{});//GEN-BEGIN:|126-getter|1|126-postInit
            form.addCommand(getBackCommand10());
            form.setCommandListener(this);//GEN-END:|126-getter|1|126-postInit
            // write post-init user code here
        }//GEN-BEGIN:|126-getter|2|
        return form;
    }
//</editor-fold>//GEN-END:|126-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand10 ">//GEN-BEGIN:|127-getter|0|127-preInit
    /**
     * Returns an initialized instance of backCommand10 component.
     *
     * @return the initialized component instance
     */
    public Command getBackCommand10() {
        if (backCommand10 == null) {//GEN-END:|127-getter|0|127-preInit
            // write pre-init user code here
            backCommand10 = new Command("Back", Command.BACK, 0);//GEN-LINE:|127-getter|1|127-postInit
            // write post-init user code here
        }//GEN-BEGIN:|127-getter|2|
        return backCommand10;
    }
//</editor-fold>//GEN-END:|127-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: textBox1 ">//GEN-BEGIN:|117-getter|0|117-preInit
    /**
     * Returns an initialized instance of textBox1 component.
     *
     * @return the initialized component instance
     */
    public TextBox getTextBox1() {
        if (textBox1 == null) {//GEN-END:|117-getter|0|117-preInit
            // write pre-init user code here
            textBox1 = new TextBox("Ingrese c\u00F3digo", null, 100, TextField.ANY);//GEN-BEGIN:|117-getter|1|117-postInit
            textBox1.addCommand(getOkCommand8());
            textBox1.addCommand(getBackCommand9());
            textBox1.setCommandListener(this);//GEN-END:|117-getter|1|117-postInit
            // write post-init user code here
            str=textBox1.getString();
        }//GEN-BEGIN:|117-getter|2|
        return textBox1;
    }
//</editor-fold>//GEN-END:|117-getter|2|
    
      


    public void destroyApp(boolean unconditional) {
    }
    
    /**
     * Returns a display instance.
     *
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started. Checks whether the MIDlet have been
     * already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     *
     * @param unconditional if true, then the MIDlet has to be unconditionally
     * terminated and all resources has to be released.
     */
}
